﻿using Project.API.Models;
using Project.BLL;
using Project.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace Project.API.Controllers
{
    public class CartController : ApiController
    {
        CartBll bll = new CartBll();
        Entities model = new Entities();

        // GET: api/Cart
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET: api/Cart/5
        public string Get(int id)
        {
            return "value";
        }

        // POST: api/Cart
        public int Post([FromBody]CartDto value)
        {
            milktea_cart cart = new milktea_cart();
            cart.cart_id = value.cid;
            cart.zong_price = value.price;
            cart.quantity = value.quantity;
            cart.add_time = value.datetime;
            cart.Dstatus = value.dstatus;

            int id = bll.AddCart(cart);

            return id;
        }

        // PUT: api/Cart/5
        public void Put(int id, [FromBody]string value)
        {
        }


        [Route("Api/Cart/QuXiao")]
        // DELETE: api/CartDetail/5
        public int DeleteQuXiao(int id)
        {

            var list = model.milktea_cart_detail.Where(d => d.Cart_id == id);

            model.milktea_cart_detail.RemoveRange(list);

            model.SaveChanges();

            var data = model.milktea_cart.Where(c => c.cart_id == id).FirstOrDefault();

            model.milktea_cart.Remove(data);

            model.SaveChanges();

            return 0;

        }

        // DELETE: api/Cart/5
        public void Delete(int id)
        {
        }
    }
}
